package org.jeecg.client;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
 * @author bright
 * 业务请求对象
 */
public class BizRequest implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	static String REQUEST = "<req><clnt>%s</clnt><prg>%s</prg><enty>%s</enty><cmd>%s</cmd><pid>%s</pid><pt>1</pt><pars>%s</pars><lang>%s</lang><svr>%s</svr><uid>%s</uid><pwd>%s</pwd></req>";

	
	private String clientId;
	private String serverId;
	private String entityId;
	private String lang;
	private String cmdName;
	private String program;
	private String processId;
	private String userId;
	private String password;
	private Map<String, String> parameters;
	
	public String getParameter(String name){
		return parameters == null ? null : (parameters.containsKey(name) ? parameters.get(name) : null);
	}
	
	public void setParameter(String name, String value){
		if (null == parameters)
			parameters = new HashMap<String, String>();
		parameters.put(name, value);
	}
		
	/**
	 * 将Request对象转换为xml格式的String
	 */
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		if (null != parameters)
			for(Map.Entry<String, String> e : parameters.entrySet()){
				sb.append(String.format("<p name=\"%s\"><![CDATA[%s]]></p>", e.getKey(), e.getValue()));
			}
		
		return String.format(REQUEST, clientId, program, entityId, cmdName, processId, sb.toString(), lang, serverId, userId, password);
	}

	public String getClientId() {
		return clientId;
	}
	public void setClientId(String clientId) {
		this.clientId = clientId;
	}
	public String getServerId() {
		return serverId;
	}
	public void setServerId(String serverId) {
		this.serverId = serverId;
	}
	public String getEntityId() {
		return entityId;
	}
	public void setEntityId(String entityId) {
		this.entityId = entityId;
	}
	public String getCmdName() {
		return cmdName;
	}
	public void setCmdName(String cmdName) {
		this.cmdName = cmdName;
	}
	public String getProgram() {
		return program;
	}
	public void setProgram(String program) {
		this.program = program;
	}
	public String getLang() {
		return lang;
	}
	public void setLang(String lang) {
		this.lang = lang;
	}
	public String getProcessId() {
		return processId;
	}
	public void setProcessId(String processId) {
		this.processId = processId;
	}
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the parameters
	 */
	public Map<String, String> getParameters() {
		return parameters;
	}

	/**
	 * @param parameters the parameters to set
	 */
	public void setParameters(Map<String, String> parameters) {
		this.parameters = parameters;
	}
}
